<?php
namespace app\api\controller\wine;


use app\api\controller\Controller;
use app\api\model\wine\Dermember as DermemberModel;
use think\App;

class Dealer extends Controller {
    private $userArr = [];
    private $DerMermModer;
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->userArr = $this->getLoginUser();
        $this->DerMermModer = new DermemberModel();
    }

    //注册经销商
    public function regist(){
        $data = $this->postForm();
        $user_id = $this->userArr['user_id'];
        $data['user_id'] = $user_id;
        $addValidate = new \app\api\validate\wine\Dealer();
        if(!$addValidate->check($data)){
            return $this->renderError($addValidate->getError());
        }
        if($this->DerMermModer->add($data)){
            return $this->renderSuccess([],'经销商成功注册或更新');
        }else{
            return $this->renderError('经销商注册失败');
        }
    }

    //获取经销商信息
    public function getder(){
        $user_id = $this->userArr['user_id'];
        $derinfo = $this->DerMermModer->getDerInfo($user_id);
        if(empty($derinfo)){
            return $this->renderError('经销商信息获取失败');
        }
        return $this->renderSuccess(compact('derinfo'),'经销商信息获取成功');
    }
}
